# coding: utf-8
# @Author: cyl
import os
import time
import logging
from setting import LOG_PATH


# @singleton
class Logger:
    """日志"""
    logger = None

    @classmethod
    def get_logger(cls):
        # 2024-10-26.log
        if cls.logger is None:
            cls.log_name = os.path.join(LOG_PATH, "{}.log".format(time.strftime("%Y%m%d")))
            cls.logger = logging.getLogger("log")
            cls.logger.setLevel(logging.DEBUG)
            cls.for_mater = logging.Formatter('[%(asctime)s][%(filename)s %(lineno)d][%(levelname)s]: %(message)s')
            cls.file_logger = logging.FileHandler(cls.log_name, mode='a', encoding="UTF-8")
            cls.console = logging.StreamHandler()
            cls.console.setLevel(logging.DEBUG)
            cls.file_logger.setLevel(logging.DEBUG)
            cls.file_logger.setFormatter(cls.for_mater)
            cls.console.setFormatter(cls.for_mater)
            cls.logger.addHandler(cls.file_logger)
            cls.logger.addHandler(cls.console)

        return cls.logger


logger = Logger().get_logger()


"""
使用
from logger_handler import logger

logger.debug("debug级别的日志")
logger.info("info级别的日志")
logger.error("error级别的日志")
logger.warning("warning级别的日志")
"""
